package com.web;

import com.dao.FoodDao;
import com.dao.Impl.FoodImpl;
import com.pojo.Food;
import com.utils.webUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class FoodServlet extends HttpServlet {
    FoodDao foodDao=new FoodImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action=req.getParameter("action");
        if ("page".equals(action)) {
            String idd=req.getParameter("id");
            String louhaoo=req.getParameter("louhao");
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.queryFoods();
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            req.getSession().setAttribute("sushehao",idd);
            req.getSession().setAttribute("louhao",louhaoo);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("ls".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.querylsFoods("ls");
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("latiao".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.querylsFoods("latiao");
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("phsp".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.querylsFoods("phsp");
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("yl".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.querylsFoods("yl");
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("pm".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.querylsFoods("pm");
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }else if("all".equals(action)){
            //保存所有商品到books List列表中
            List<Food> foods =foodDao.queryFoods();
            //将books List列表保存到req域中
            req.setAttribute("foods", foods);
            //将req域请求转发到index页面中
            req.getRequestDispatcher("/mainindex.jsp").forward(req, resp);
        }
    }
}
